package com.java2007.hotel.controller;

import com.java2007.hotel.utils.ValidateCode;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 处理验证码请求
 * @author csl
 * @version V1.0
 * @date 2021/01/12
 **/
@WebServlet("/validateCode")
public class VerificationServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ValidateCode validateCode = new ValidateCode();
        validateCode.createCode();
        String code = validateCode.getCode();
        req.getSession().setAttribute("validateCode",code);
        validateCode.write(resp.getOutputStream());
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
